using System;
using System.Collections.Generic;
using System.Text;

namespace net.notdot.Attercop
{
    /// <summary>
    /// Provides a handle to an ongoing search query.
    /// </summary>
    public class Query
    {
        private static Random rand = new Random();

        internal event EventHandler<MessageEventArgs<SearchResultMessage>> OnResult;
        internal int SearchNo;

        internal Query(EventHandler<MessageEventArgs<SearchResultMessage>> handler)
        {
            this.SearchNo = rand.Next();
            this.OnResult += handler;
        }

        internal void Raise(object sender, SearchResultMessage message) {
            if (OnResult != null)
                OnResult(sender, new MessageEventArgs<SearchResultMessage>(message));
        }
    }
}
